package com.lzw.count_down;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.view.SimpleDraweeView;

public class MainActivity extends AppCompatActivity {
    private static final int LL = 1;
    private TextView tv;
    private int i=10;
    private Handler handler = new Handler(){


        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (i==0){
                i=10;
//
                startActivity(new Intent(MainActivity.this,InfoActivity.class));
                finish();
                return;

            }
            but.setText(String.valueOf(--i));
            Message message = Message.obtain();
            handler.sendEmptyMessageDelayed(1,1000);
        }
    };
    private SimpleDraweeView sdv;
    private Button but;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Fresco.initialize(this);
        setContentView(R.layout.activity_main);
//        tv = (TextView) findViewById(R.id.tv);
        but = (Button) findViewById(R.id.but);
        sdv = (SimpleDraweeView) findViewById(R.id.sdv);
        sdv.setImageResource(R.mipmap.ic_launcher_round);

        Message message = Message.obtain();
        message.what = LL;
        handler.sendEmptyMessageDelayed(message.what, 1000);
    }
    public void onClick(View v){
        switch (v.getId()) {

            case R.id.but:
                startActivity(new Intent(this,InfoActivity.class));
//                handler.removeMessages(LL);
                finish();
                break;
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        handler.removeMessages(LL);
    }
}
